import PlayerControl from "./PlayerControl";

const { ccclass, property } = cc._decorator;

@ccclass
export default class EnemyControl extends cc.Component {

	isDie: boolean = false

	start() {

	}

	// 死亡
	die() {
		this.isDie = true
		// 加载爆炸图片
		cc.loader.loadRes("enemy0_die", cc.SpriteFrame, (err, res) => {
			this.node.getComponent(cc.Sprite).spriteFrame = res;
		})
		setTimeout(() => {
			this.node.destroy()
		}, 300)
	}

	update(dt) {
		if (!this.isDie) {
			this.node.y -= 300 * dt
		}
		if (this.node.y < -820) {
			this.node.destroy()
		}
	}
	// 如果碰到玩家，销毁自己，让玩家死亡
	onCollisionEnter(other) {
		// 销毁敌人
		other.getComponent(PlayerControl).die()
		// 销毁自己
		this.die()
	}
}
